package com.ea.eadp.nexus.test.pageDefinition.newconsole;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;


public class WelcomeBackPage extends ConsoleBasePage {
    public final static String loginPasswordInputBox = "loginPassword";

    public WelcomeBackPage(WebDriver driver) {
        super(driver, WelcomeBackPage.class, loginPasswordInputBox);
    }

    public void enterPassword(String password) {
        log.info("Enter Password:" + password);
        sendInput(loginPasswordInputBox, password);
        clickBlank("//div[@id='panel-login']//div[@class='titleBar']");
        sendControllerKey('A');
    }

    public void validateWrongPassword(String password, String errorMessage) {
        log.info("Validate Password:" + password);
        sendInput(loginPasswordInputBox, password);
        clickBlank("//div[@id='panel-login']//span[@class='title']");
        sendControllerKey('A');
        Assert.assertEquals(getPasswordInvalidError(), errorMessage, "Input not trigger the correct error message");
    }

    public void forgotPassword() {
        log.info("Click Forgot Password");
        sendControllerKey(Keys.DOWN);
        sendControllerKey('A');
    }

    public void validateCaptcha() {
        log.info("Validate Captcha");
        Assert.assertEquals(getCaptchaError(), "Security Check", "Not trigger the Security Check");
    }

    public void validateReminderPopup() {
        log.info("Validate Captcha");
        Assert.assertEquals(getReminderPopupError(), "Unable to Login", "Not trigger the Reminder Popup");
    }

    public String getTitle() {
        return getElementStringByXPath("//div[@id='panel-login']//span[@class='title']");
    }

    public String getDescription() {
        return getElementStringByXPath("//div[@id='panel-login']//p[@class='description']");
    }

    public String getEmailLabel() {
        return getElementStringByXPath("//div[@id='panel-login']//li[1]/span[@class='title']");
    }

    public String getEmailText() {
        return getElementStringByXPath("//div[@id='panel-login']//li[1]/span[@class='emailText']");
    }

    public String getPasswordLabel() {
        return getElementStringByXPath("//li[@class='login-password-container']//label[@class='origin-ux-textbox-label']");
    }

    public String getPasswordInvalidError() {
        return getElementStringByXPath("//li[@class='login-password-container']//span[@class='origin-ux-textbox-status-message origin-ux-status-message']");
    }

    public String getErrorMessageTitle() {
        return getElementString(By.id("error-message-title"));
    }

    public String getPasswordForgottenTip() {
        return getElementStringByXPath("//div[@id='forgetPassTooltip']/div[@class='origin-tooltip-large']");
    }

    public String getCaptchaError() {
        return getElementStringByXPath("//div[@id='panel-captcha']//span[@class='title']");
    }

    public String getReminderPopupError() {
        return getElementStringByXPath("//div[@id='modal']//h2[@class='title']");
    }
}
